package com.cloud.pole.rpc;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.pole.api.param.ParamAreaApi;
import com.cloud.pole.api.param.PicklistApi;
import com.cloud.pole.common.constant.CommonConstants;
import com.cloud.pole.common.exception.BaseException;
import com.cloud.pole.common.exception.ParamException;
import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.param.model.entity.ParamArea;
import com.cloud.pole.param.model.entity.Picklist;
import com.cloud.pole.param.service.ParamAreaService;
import com.cloud.pole.param.service.ParamPickListService;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("api/area")
public class ParamAreaRest {
	
	@Autowired
	private ParamAreaService paramAreaService;

    @RequestMapping(value = "/getProvinceList", method = RequestMethod.GET)
    public ApiRestResponse<List<ParamAreaApi>> getProvinceList(){   	
    	try {
			List<ParamArea> srcList = paramAreaService.getAreaList(ParamAreaApi.AREA_CODE_ROOT, ParamAreaApi.AREA_TYPE_PROVINCE);
			List<ParamAreaApi> descList = new ArrayList<ParamAreaApi>();
			if(srcList != null) {
				for(ParamArea paramArea : srcList) {
					ParamAreaApi paramAreaVo = new ParamAreaApi();
					BeanUtils.copyProperties(paramArea, paramAreaVo);
					descList.add(paramAreaVo);
				}
			}
			return ApiRestResponse.success(CommonConstants.STATUS_OK_MESSAGE, descList);
		} catch (BaseException e) {
			return ApiRestResponse.fail(e.getStatus(), e.getMessage(), null);
		} catch (Exception e) {
			log.error(CommonConstants.STATUS_ERROR_MESSAGE + "{}", e.getMessage(), e);
			return ApiRestResponse.fail(CommonConstants.STATUS_ERROR_MESSAGE, null);
		}
    }    
}
